﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sys_class_edit.aspx.cs" Inherits="Ccit.SysPlat.Organ.sys_class_edit" %>

<html>
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/StringClass_Ext.js"></script>
    <script type="text/javascript" src="../script/jwindow.js"></script>
    <script type="text/javascript" src="../script/jsonlib.js"></script>
    <script type="text/javascript">
      <!--
          function doCheck(vType) {
                switch(vType) {
                    case "CLASSNAME":
                        var vOrganId = $get("_hidOrganId").value;
                        var ctrlClassName = $get("txtClassName");
                        var vClassName = jQuery.trim(ctrlClassName.value);
                        if(vClassName == "") {
                            alert("级别名称不能为空!");
                            ctrlClassName.focus();
                        }
                        else {
                            var vClassId = $get("_hidClsId").value;
                             PageMethods.CheckClassNameExist(vClassId,vClassName,vOrganId,ClientCallBack);
                        }
                        break; 
                     case "ORDER":
                        var ctrlClassOrder = $get("txtClassOrder");
                        var vClassOrder = jQuery.trim(ctrlClassOrder.value);
                        if(vClassOrder != "") {
                            if(!vClassOrder.IsNumber()) {
                                alert("显示顺序只能输入整数!");
                                ctrlClassOrder.focus();
                            }
                        }                   
                }
                
          }
          
          function doCheckEmpty() {
             var vOrganId = $get("_hidOrganId").value;
             var ctrlClassName = $get("txtClassName");
             var vClassName = jQuery.trim(ctrlClassName.value);
             if(vClassName == "") {
                alert("级别名称不能为空!");
                ctrlClassName.focus();
                return false;
             }
             
             return true;
          }

          function ClientCallBack(vResult) {
            if (null == vResult || vResult == "undefined") {
                alert("网络传输错误,没有正确的返回值,请检查网络是否畅通!");
                return;
            }
            eval("var resultObj=" + vResult);
            var operType = resultObj.OPERTYPE;
            switch (operType) {
                case "CLSNAMECHECK":  
                    if (resultObj.RSTSIGN != "NOEXIST") {
                        alert(resultObj.RSTMSG);
                        var ctrlClassName = $get("txtClassName");
                        ctrlClassName.focus();
                    }         
                    break;
                case "CLSSAVE":
                    var ctrlType = resultObj.CTRLTYPE;
                    alert(resultObj.RSTMSG);
                    switch (ctrlType) {
                        case "1":
                            var curClsId = $get("_hidClsId").value;
                            var msCls = {};
                            msCls.clsId = resultObj.RSTSIGN;
                            msCls.clsName = jQuery.trim($get("txtClassName").value);
                            var jsonExpr = JSON.stringify(msCls, function(key, value) { return value; });
                            var isAddNew = (curClsId == "") ? "0" : "1";
                            parent.frames[0].document.getElementById("_hidCurClsExpr").value = jsonExpr;
                            parent.frames[0].document.getElementById("_hidAddNewSign").value = isAddNew;
                            parent.frames[0].document.all.btnTrigger.click();
                            $get("_hidClsId").value = resultObj.RSTSIGN;
                            var ctrlDel = $get("btnDel");
                            ctrlDel.style.visibility = "visible";
                            break;
                        case "2":
                            initAddNew();
                            break;
                    }
                    break;
                case "CLSDELETE":
                    alert(resultObj.RSTMSG);
                    if (parseInt(resultObj.RSTSIGN) > 0) {
                        var clsId = $get("_hidClsId").value;
                        parent.frames[0].document.getElementById("_hidDelClsId").value = clsId;
                        parent.frames[0].document.all.btnDelTrigger.click();
                        //                        initAddNew();
                    }                   
                    break; 
            }
            resultObj = null;
          }
      
          function doSave(ctrlType) {
                if(!doCheckEmpty()) return ;
                
                saveData(ctrlType);
          }

          function saveData(ctrlType) {
              var msCls = {};
              msCls.clsId = $get("_hidClsId").value;
              msCls.clsName = jQuery.trim($get("txtClassName").value);
              msCls.clsDesc = $get("txtClassDesc").value;
              msCls.orderNo = $get("txtClassOrder").value;

              var msOrgan = {};
              msOrgan.organId = $get("_hidOrganId").value;

              var includeUsers = {};
              includeUsers.key = $get("_hidSelUser").value;

              msCls.belongOrgan = msOrgan;
              msCls.includeUsers = includeUsers;

              var jsonExpr = JSON.stringify(msCls, function(key, value) { return value; });
              PageMethods.SaveClsData(jsonExpr, ctrlType, ClientCallBack);
              msCls = null;          
          }
          
          function initAddNew() {
            $get("_hidClsId").value = "";
            $get("txtClassName").value = "";
            $get("txtClassDesc").value = "";            
            $get("_hidSelUser").value = "";
            $get("txtSelUser").value = "";
            $get("txtClassOrder").value = "";
            
            var ctrlDel = $get("btnDel");
            ctrlDel.style.visibility = "hidden";
          }
          
          function doDelete() {
              if(!confirm("删除本职位记录,是否继续?")) return;
                
              var clsId = $get("_hidClsId").value;
              PageMethods.DeleteCls(clsId, ClientCallBack);
          }
          
          function doSelUser(vCtrlId,vCtrlName) {
                OpenUserMultiSelect(vCtrlId,vCtrlName,"1");
          }
      //-->
    </script>
</head>
<body scroll="no">
    <form id="form1" runat="server">  
    <input type="hidden" id="_hidOrganId" runat="server" />
    <input type="hidden" id="_hidClsId" runat="server" />  
    <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    </asp:ScriptManager>
    <table class="tableborder" cellpadding="0" cellspacing="0" width="98%" align="center">
        <tr>
            <td width="15%" align="right" class="pformleft"><nobr><font color='red'><b>*</b></font>级别名称</nobr></td>
            <td width="35%" class="pformrightline">
                <asp:TextBox ID="txtClassName" onblur="doCheck('CLASSNAME')" CssClass="input" Width="98%" runat="server"></asp:TextBox>
            </td>                
            <td width="15%" align="right" class="pformleft"><nobr>显示顺序</nobr></td>
            <td width="35%" class="pformright" valign="middle">
                <nobr>
                    <asp:TextBox ID="txtClassOrder" onblur="doCheck('ORDER')" Width="40px" runat="server"></asp:TextBox>
                    &nbsp;<font color="blue" face='Arial' size='1.5'><i><b>注: 为空则由系统默认生成</b></i></font>
                </nobr>
            </td>
        </tr>
        <tr>
            <td width="10%" align="right" valign="top" class="pformleft"><nobr>级别描述</nobr></td>
            <td width="90%" class="pformright" colspan="3">
                <asp:TextBox ID="txtClassDesc" TextMode="MultiLine" Width="99.3%" Rows="4" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td width="10%" align="right" valign="top" class="pformleft">
                级别成员<br />
                    <a href="javascript:doSelUser('_hidSelUser','txtSelUser')">
                        <img src="../images/toolbar/user.gif" border="0" /></a>
                
            </td>
            <td width="90%" class="pformright" colspan="3">
                <input type="hidden" id="_hidSelUser" runat="server" />
                <asp:TextBox ID="txtSelUser" TextMode="MultiLine" Width="99.3%" Rows="8" runat="server"></asp:TextBox>                    
            </td>
        </tr>
        <tr class="pformstrip">
            <td colspan="4" align="center">
                <input type="button" id="btnSave" class="button" onclick="doSave('1')" value="保存" />
                &nbsp;
                <input type="button" id="btnSaveAdd" class="button" onclick="doSave('2')" value="保存并新增" />
                &nbsp;
                <input type="button" id="btnDel" class="button" onclick="doDelete()" value="删除" />
            </td>
        </tr>            
    </table>
    </form>
    <script type="text/javascript">
    <!--
        $(document).ready(function() {
            var clsId = jQuery.trim($get("_hidClsId").value);
            var ctrlDel = $get("btnDel");
            ctrlDel.style.visibility = (clsId == "") ? "hidden" : "visible";            
        });
    //-->
    </script>
</body>
</html>
